<script setup lang="ts">
import {onLaunch, onShow, onHide} from "@dcloudio/uni-app";
import routerIntercept from "@/utils/routerIntercept";
import {bindTIMEvent,login} from '@/utils/IM'
import user from "@/store/user";

const userStore = user()
userStore.weixinLogin().then(res => {
  console.log('res', res)
  // 登录IM（如果有name则说明已经授权获取过用户信息，可以取到用户名和头像）
  if(userStore.userInfo?.name){
    login(userStore.userInfo.uId)
  }else{
    // 第一次登录，需要用户手动设置用户名和头像
    uni.navigateTo({
      url: '/pages/auth/index'
    })
  }
})

onLaunch(() => {
  // 初始化路由拦截
  routerIntercept()
  // 绑定IM事件
  bindTIMEvent();
  // login('textUser')
  console.log("App Launch");
});
onShow(() => {
  console.log("App Show");
});
onHide(() => {
  console.log("App Hide");
});
</script>
<style lang="scss">
@import "@/uni_modules/uview-plus/index.scss";
page {
  background-color: #F8F8F8;
  height: 100%;
}
</style>
